<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<base href="http://localhost:8080/pluploadDemo/" />
<title>Plupload - Custom example</title>
<link rel="stylesheet" href="/pluploadDemo/progressbar/css/common.css" type="text/css" />
<!-- production -->
<script type="text/javascript" src="/pluploadDemo/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/pluploadDemo/js/plupload.full.min.js"></script>
<script type="text/javascript" src="/pluploadDemo/progressbar/jquery.progressbar.js"></script>

<!-- debug 
<script type="text/javascript" src="../js/moxie.js"></script>
<script type="text/javascript" src="../js/plupload.dev.js"></script>
-->

</head>
<body style="font: 13px Verdana; background: #eee; color: #333">


<div id="filelist">浏览器加载控件失败，请更换浏览器重试！</div>
<br />
<div id="proDiv"></div>

<div id="container">
    <a id="pickfiles" href="javascript:;">[Select files]</a> 
    <a id="uploadfiles" href="javascript:;">[Upload files]</a>
</div>

<br />
<pre id="console"></pre>


<script type="text/javascript">

var uploader = new plupload.Uploader({
	runtimes : 'html5,flash,silverlight,html4',
	browse_button : 'pickfiles', // you can pass in id...
	container: document.getElementById('container'), // ... or DOM Element itself
	url : 'fileUpload',
	flash_swf_url : 'js/Moxie.swf',
	silverlight_xap_url : 'js/Moxie.xap',
	unique_names:true,
	filters : {
		max_file_size : '2mb',
		mime_types: [
			{title : "Image files", extensions : "jpg,gif,png"},
			{title : "Zip files", extensions : "zip"}
		]
	},

	init: {
		PostInit: function() {
			document.getElementById('filelist').innerHTML = '';

			document.getElementById('uploadfiles').onclick = function() {
				uploader.start();
				console.log("文件开始上传...");
				return false;
			};
		},

		FilesAdded: function(up, files) {
			plupload.each(files, function(file) {
				document.getElementById('filelist').innerHTML += '<div id="' + com.project.common.web.utils.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
				$("#proDiv").html($("#proDiv").html()+"<span id='pro_"+com.project.common.web.utils.id+"' class='procgressBar'/>");
				$("#pro_"+com.project.common.web.utils.id).progressBar();
				console.log("添加了文件："+file.name+",id:"+com.project.common.web.utils.id+",文件大小："+plupload.formatSize(file.size));
			});
		},

		UploadProgress: function(up, file) {
			//document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
			console.log("文件："+file.name+",总大小："+file.size+",已上传了："+file.loaded+",进度:"+file.percent);
		},
		
		UploadFile: function(up,file){
			console.log("文件上传准备："+file.name);
		},
		
		UploadComplete: function(up,files){
			plupload.each(files,function(file){
				console.log("文件上传完成："+file.name);
			});
		},
		
		Error: function(up, err) {
			//document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
			console.log("发生错误:"+err.code+":"+err.message);
		}
	}
});

uploader.init();

</script>
</body>
</html>
